refactor(storage): dedupe repeated u128 little-endian decode into a helper - #1585
Closed
minion1227 wants to merge 2 commits into
Closed
refactor(storage): dedupe repeated u128 little-endian decode into a helper#1585minion1227 wants to merge 2 commits into
minion1227 wants to merge 2 commits into
Conversation
The little-endian u128 reconstruction — `lo, hi = struct.unpack_from('<QQ',
data, offset)` then `lo + (hi << 64)` — was repeated verbatim three times
(alpha_pool, bounty_amount, target_bounty). Fold it into a named
_decode_u128le helper so the intent is explicit and the '<QQ' format lives
in one place. Behavior-preserving; already covered by the round-trip tests
in test_issue_competitions_storage_utils.py (incl. max-u64 high-limb cases).
Pre-existing drift on `test`: under the pinned ruff 0.15.12 the split f-string in issues_submissions collapses onto one line. --all-files surfaces it on any fork PR. No behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The little-endian u128 reconstruction —
lo, hi = struct.unpack_from('<QQ', data, offset)thenlo + (hi << 64)— was repeated verbatim three times instorage_utils.pywhen decodingalpha_pool,bounty_amount, andtarget_bounty. This folds it into a single named_decode_u128le(data, offset)helper so the intent is explicit and the'<QQ'limb layout lives in one place.Pure structural change — identical decoded values, and the
struct.error/IndexErrorraised bystruct.unpack_fromstill propagates to the same enclosingtry/exceptas before.The second commit is a one-line
ruff formatfix tosubmissions.py(pre-existing--all-filesdrift ontestfrom the ruff 0.15.12 bump) so this PR's fork CI is green; no behavior change, happy to split it out if preferred.Related Issues
None — small internal refactor.
Type of Change
Testing
ruff+pyrightclean;pre-commit run --all-filespasses.tests/utils/test_issue_competitions_storage_utils.pyalready exercise all three decode paths, including the nonzero-high-limb / max-u64 cases (test_decode_packed_contract_storage_handles_maximum_field_values).Checklist